package com.mgg.message.controller.notify;

import java.util.List;
import java.util.Map;

import com.mgg.common.util.ResultVOUtil;
import com.mgg.message.service.notify.NotifyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/notify")
public class NotifyController {
	
	Logger log = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private NotifyService notifyService;
	
	/**
	 * 未读消息统计
	 * @return
	 * @throws Exception
	 */
	@GetMapping(path="/count")
	public Object getUnReadNotifyCount(@RequestHeader("user_id") String userId) throws Exception {
		return ResultVOUtil.success(notifyService.getUnReadNotifyCount(userId));
	}
	
	/**
	 * 消息通知中心
	 * @return
	 * @throws Exception
	 */
	@GetMapping(path="/index")
	public Object getUserMessageNotifyIndex(@RequestHeader("user_id") String userId) throws Exception {
		return ResultVOUtil.success(notifyService.listNotifyIndex(userId));
	}
	
	/**
	 * 消息列表
	 * @return
	 * @throws Exception
	 */
	@GetMapping(path="/list")
	public Object getUserMessageNotifyList(@RequestHeader("user_id") String userId, @RequestParam("msg_type") String msgType,
			@PageableDefault(page = 1, size = 10) Pageable page) throws Exception {
		List<Map<String,Object>> notifyList = notifyService.listNotifyByUserIdAndType(userId, msgType, page);
		return ResultVOUtil.success(notifyList);
	}
}
